package com.user.query.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.user.query.model.Menu;
import com.user.query.service.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.user.query.model.User;

import java.util.List;

@Controller
public class LoginController extends BaseController{

	@Resource
	private MenuService menuService;

	/**
	 * 后台主页面
	 * @param request
	 * @return
	 */
	@RequestMapping("/defaultPage")
	public ModelAndView defaultPage(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("/comm/main");
		try {
			User loginUser = getCurrentUser(request);
//			List<Menu> list = menuService.queryByLoginUser(loginUser);
			List<Menu> list = menuService.queryAllEffective();

			view.addObject("list", list);
		} catch (Exception e) {
			log.info("主页面异常：" + e);
		}
		return view;
	}

	@RequestMapping("/")
	public ModelAndView toLogin(HttpServletRequest request) throws Exception {
	/*	User loginUser = getCurrentUser(request);
		if(loginUser !=null){*/
			ModelAndView view = new ModelAndView("/index");
			return view;
	/*	}else{
			ModelAndView view = new ModelAndView("/index");
			return view;
		}*/
	}

}
